import { GetServerSideProps } from "next"
import PageLayout from "../segments/PageLayout"
import TopicEntry from "../segments/TopicEntry"
import Head from "next/head"

import { Book } from "../types"
import { getAllBooks } from "../server/app/BookService"

const HomePage: React.FC<{ books: Book[] }> = ({ books }) => {
  return (
    <PageLayout>
      <Head>
        <title>主页</title>
      </Head>
      {books.map((book) => (
        <TopicEntry key={book.path} title={book.title} url={"/b/" + book.path} />
      ))}
    </PageLayout>
  )
}

export default HomePage

export const getServerSideProps: GetServerSideProps = async () => {
  const books = await getAllBooks()
  return { props: { books } }
}
